package com.ldg.manager.controller;

import java.util.Arrays;
import java.util.Map;

import com.ld.utils.PageUtils;
import com.ld.pojo.R;
import com.ldg.manager.client.UserClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import com.ldg.manager.entity.BrandEntity;
import com.ldg.manager.service.BrandService;




/**
 * 品牌
 *
 * @author LD
 * @email 419631142@qq.com
 * @date 2022-09-12 18:39:33
 */
@RestController
@RequestMapping("brand")
public class BrandController {
    @Autowired
    private BrandService brandService;
    @Autowired
    private UserClient userClient;
    @Value("${server.port}")
    private String port;
    /**
     * 列表
     */
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = brandService.queryPage(params);

        return R.ok().put("page", page);
    }

    @GetMapping("findAll")
    public R findAll(){
        return R.ok().put("list",brandService.list()).put("port",port);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") String id){
		BrandEntity brand = brandService.getById(id);

        return R.ok().put("brand", brand);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody BrandEntity brand){
		brandService.save(brand);

        return R.ok();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public R update(@RequestBody BrandEntity brand){
		brandService.updateById(brand);

        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public R delete(@RequestBody String[] ids){
		brandService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    @GetMapping("/user/findAll")
    public R userfindAll(){
        return userClient.findAll();
    }
}
